import 'package:flutter/material.dart';
import '../api/auth_api.dart';

class MainScreen extends StatelessWidget {
  const MainScreen({super.key});

  Future<void> _logout(BuildContext context) async {
    try {
      await AuthApi.logout();
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('已成功登出')),
      );
      Navigator.popUntil(context, (route) => route.isFirst);
    } catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('登出失败: $e')),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('会议室预订系统'),
        actions: [
          IconButton(
            icon: const Icon(Icons.exit_to_app),
            onPressed: () => _logout(context),
          ),
        ],
      ),
      body: const Center(
        child: Text('欢迎使用会议室预订系统'),
      ),
    );
  }
}
